copyq:

popup("上传中", "请等待");

var img_formats = ["text/plain", "text/html", "image/jpeg", "image/png", "image/gif"]

data = ""
for (var i = 0; i < img_formats.length; i++) {
    imageData = read(img_formats[i], 0)
    if (str(imageData).length != 0) {
        data = imageData
        break
    }
}
// 1. file:///xxx
// 2. html(img) src含有http链接指向图片
// 3. 图片的像素格式数据

data = execute('python', 'upload_image/html_handler.py', null, data).stdout;

data = execute('python', 'upload_image/file_link_handler.py', null, data).stdout;

data = execute('python', 'upload_image/image_uploader.py', null, data).stdout;

data = execute('python', 'upload_image/filter.py', null, data).stdout;

var http_link = str(data);

if (str(http_link) != 0) {
    markdown_link = "![](" + http_link + ")";
    insert(0, markdown_link);
    insert(1, http_link);
    insert(2, "[------end of new link------]");
    popup("上传成功", http_link);
    copy(markdown_link);
    paste();
}
else {
    popup("上传失败");
}
